package com.cos.hospital.widget;

import android.content.Context;
import android.support.constraint.ConstraintLayout;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.cos.hospital.R;
import com.cos.hospital.tool.UTxt;
import com.cos.hospital.tool.glide.UGlide;
import com.cos.hospital.ui.other.YinShiTuPianActivity;

import java.util.ArrayList;
import java.util.List;

public class MultImageView extends ConstraintLayout {
    ImageView image1, image2, image3;
    ArrayList<String> imageList;
    LinearLayout contentLayout;

    public MultImageView(Context context) {
        this(context, null);
    }

    public MultImageView(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public MultImageView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        inflate(context, R.layout.lay_mult_image, this);
        image1 = findViewById(R.id.rec_tongue_img_1);
        image2 = findViewById(R.id.rec_tongue_img_2);
        image3 = findViewById(R.id.rec_tongue_img_3);
        contentLayout = findViewById(R.id.content);
        image1.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                YinShiTuPianActivity.showTuPian(context, imageList, 0);

            }
        });
        image2.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                YinShiTuPianActivity.showTuPian(context, imageList, 1);

            }
        });
        image3.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                YinShiTuPianActivity.showTuPian(context, imageList, 2);
            }
        });
    }

    public void setImages(List<String> list) {
        ArrayList list1 = new ArrayList();
        if (list != null && list.size() > 0) {
            for (String s : list) {
                list1.add(s);
            }
        }
        imageList = list1;
        update();
    }

    public void update() {
        int tongueSize = UTxt.getSize(imageList);
        if (tongueSize < 1) {
            contentLayout.setVisibility(View.GONE);

        } else if (tongueSize == 1) {
            contentLayout.setVisibility(View.VISIBLE);
            image1.setVisibility(View.VISIBLE);
            image2.setVisibility(View.GONE);
            image3.setVisibility(View.GONE);
            UGlide.loadRound(getContext(), imageList.get(0), image1);
        } else if (tongueSize == 2) {
            contentLayout.setVisibility(View.VISIBLE);
            image1.setVisibility(View.VISIBLE);
            image2.setVisibility(View.VISIBLE);
            image3.setVisibility(View.GONE);
            UGlide.loadRound(getContext(), imageList.get(0), image1);
            UGlide.loadRound(getContext(), imageList.get(1), image2);
        } else {
            contentLayout.setVisibility(View.VISIBLE);
            image1.setVisibility(View.VISIBLE);
            image2.setVisibility(View.VISIBLE);
            image3.setVisibility(View.VISIBLE);
            UGlide.loadRound(getContext(), imageList.get(0), image1);
            UGlide.loadRound(getContext(), imageList.get(1), image2);
            UGlide.loadRound(getContext(), imageList.get(2), image3);
        }
    }
}
